<template>
    <div>
                <div style="margin-top:20px">
                    <!--搜索-->
                    <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
                        <el-form-item label="牌号：">
                            <el-select
                                    @change="changekingId"
                                    clearable
                                    v-model="listQuery.kingId"
                                    filterable
                                    remote
                                    reserve-keyword
                                    placeholder="请输入关键词"
                                    :remote-method="remoteMethod"
                                    :loading="loading">
                                <el-option
                                        v-for="item in options"
                                        :key="item.kingId"
                                        :label="item.goodsSn"
                                        :value="item.kingId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="合同号：">
                            <el-input v-model="listQuery.orderSn"></el-input>
                        </el-form-item>
                        <el-form-item label="品名：">
                            <el-input v-model="listQuery.goodsName"></el-input>
                        </el-form-item>
                        <el-form-item label="客户名称：">
                            <el-select
                                    @change="handleSelectCustomerName"
                                    clearable
                                    v-model="listQuery.customerName"
                                    filterable
                                    remote
                                    reserve-keyword
                                    placeholder="请输入关键词"
                                    :remote-method="querySearch"
                                    :loading="loading"
                                    style="width: 260px;">
                                <el-option
                                        v-for="item in querySearchList"
                                        :key="item.customerName"
                                        :label="item.customerName"
                                        :value="item.customerName">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="业务员：">
                            <el-select v-model="listQuery.userId" filterable placeholder="请选择" clearable @change="changeUserId">
                                <el-option
                                        v-for="item in userOptionList"
                                        :key="item.userId"
                                        :label="item.realName"
                                        :value="item.userId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <el-button
                                    @click="changeMonth('','',currentMonth)"
                                    type="primary">
                                查询
                            </el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <full-calendar :events="fcEvents" lang="zh" @changeMonth="changeMonth" @dayClick="dayClick" ></full-calendar>

                <!--筛选-->
                <el-menu :default-active="listQuery2.tab" class="el-menu-demo" mode="horizontal" @select="selectTab">
                    <el-menu-item index="1">需安排</el-menu-item>
                    <el-menu-item index="2">已安排</el-menu-item>
                </el-menu>
                <div style="background: #f5f7fa;padding:15px 15px 0 15px;border:1px solid #EBEEF5;border-bottom:0.5px solid #EBEEF5;margin-top:20px;">
                    <el-form :inline="true" :model="listQuery2" size="mini" label-width="100px">
                        <el-form-item label="是否安排：" v-if="listQuery2.tab==1">
                            <el-select @change="handleSearchList()" v-model="listQuery2.planDeliverState" filterable placeholder="请选择" clearable>
                                <el-option
                                        :key="0"
                                        label="未安排"
                                        :value="0">
                                </el-option>
                                <el-option
                                        :key="1"
                                        label="部分安排"
                                        :value="1">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="是否确定：" v-if="listQuery2.tab==2">
                            <el-select @change="handleSearchList()" v-model="listQuery2.isSure" filterable placeholder="请选择" clearable>
                                <el-option
                                        :key="0"
                                        label="不确定"
                                        :value="0">
                                </el-option>
                                <el-option
                                        :key="1"
                                        label="确定"
                                        :value="1">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="牌号：">
                            <el-select @change="handleSearchList()" v-model="listQuery2.kingId" filterable placeholder="请选择" multiple :disabled="listQuery.kingId ? true : false">
                                <el-option
                                        v-for="item in  kingIds"
                                        :key="item.goodsKingId"
                                        :label="item.goodsSn"
                                        :value="item.goodsKingId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="客户名称：">
                            <el-select @change="handleSearchList()" v-model="listQuery2.customerName" filterable placeholder="请选择" clearable :disabled="listQuery.customerName ? true : false">
                            <el-option
                                    v-for="item in  customers"
                                    :key="item.customerName"
                                    :label="item.customerName"
                                    :value="item.customerName">
                            </el-option>
                        </el-select>
                        </el-form-item>
                        <el-form-item label="业务员：">
                            <el-select @change="handleSearchList()" v-model="listQuery2.userId" filterable placeholder="请选择" clearable :disabled="listQuery.userId ? true :false">
                                <el-option
                                        v-for="item in users"
                                        :key="item.userId"
                                        :label="item.userRealName"
                                        :value="item.userId">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="发货类型："  v-if="listQuery2.tab==1">
                          <el-select v-model="listQuery2.sendTypeName" @change="handleSearchList()" clearable>
                            <el-option value="公司发货">公司发货</el-option>
                            <el-option value="采购发货">采购发货</el-option>
                            <el-option value="客户自提">客户自提</el-option>
                          </el-select>
                        </el-form-item>

                        <el-form-item label="预计发货仓库：" v-if="listQuery2.tab==1">
                          <el-input v-model="listQuery2.warehouseName" @change="handleSearchList()"></el-input>
                        </el-form-item>

                        <el-form-item label="排序：" v-if="listQuery2.tab==1">
                           <el-select v-model="listQuery2.orderBy" @change="handleSearchList()">
                              <el-option value="default" label="默认排序"></el-option>
                              <el-option value="financeTime" label="审核时间"></el-option>
                           </el-select>
                        </el-form-item>

<!--                        <el-form-item style="margin-bottom:0">-->
<!--                            <el-button-->
<!--                                    @click="handleSearchList()"-->
<!--                                    type="primary">-->
<!--                                查询-->
<!--                            </el-button>-->
<!--                        </el-form-item>-->
                    </el-form>
                </div>
                <!--数据列表-->
                <div class="table-container" style="margin-top:0px">
                    <el-table
                            v-if="listQuery2.tab==1"
                            v-loading="listLoading"
                            :data="tableData"
                            border
                            style="width: 100%">
                        <el-table-column
                                label="合同号"
                                width="150"
                                align="center">
                            <template slot-scope="scope">
                                <el-link @click="toDetail(scope.row)" type="primary"  style="font-size:12px">
                                    {{scope.row.orderSn}}
                                </el-link>
                                <img src="../../../assets/images/yue.png" v-if="scope.row.isTimeSure == 1" style="vertical-align: middle;"/>
                                <img src="https://pic.moresu.com/FhIaQcrC8Mbtqn9EmG4uteNBibd7" v-if="scope.row.activityType == 'paiMai'"  style="vertical-align: middle;width:16px"/>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="安排状态"
                                width="100"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.planDeliverState | fifterState}}
                            </template>
                        </el-table-column>
                        <el-table-column  label="订单时间" width="100">
                            <template slot-scope="scope">
                                <div>
                                    <span style="font-size:12px;vertical-align: middle">{{scope.row.createTime}}</span>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="期望发货时间"
                                width="150"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.expectSendDate}}
                                <span style="background: red;color:#fff;padding:0 5px;border-radius: 5px" v-if="scope.row.urgentType == '必须'">必须</span>
                                <span style="background:#ff6600;color:#fff;padding:0 5px;border-radius: 5px" v-if="scope.row.urgentType == '可延1-2天'">1-2天</span>
                                <span style="background:#ff9900;color:#fff;padding:0 5px;border-radius: 5px" v-if="scope.row.urgentType == '可延1-2周'">1-2周</span>
                                <span style="background:#0099ff;color:#fff;padding:0 5px;border-radius: 5px" v-if="scope.row.urgentType == '等客户通知'">等待</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="合同约定时间"
                                width="100"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.timeSureDate}}
                            </template>
                        </el-table-column>
                        <el-table-column
                          label="财务审核时间"
                          width="100"
                          align="center">
                          <template slot-scope="scope">
                            {{scope.row.financeTime}}
                          </template>
                        </el-table-column>
                        <el-table-column
                                label="商品信息"
                                width="200">
                            <template slot-scope="scope">
                                {{scope.row.goodsSn}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="客户名称"
                                width="200">
                            <template slot-scope="scope">
                                {{scope.row.customerName}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                align="center"
                                label="业务员"
                                width="100">
                            <template slot-scope="scope">
                                {{scope.row.userRealName}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                width="100"
                                label="合同单价">
                            <template slot-scope="scope">
                                {{scope.row.goodsPrice}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                prop="goodsNum"
                                label="合同数量"
                                width="100"
                                align="center">
                        </el-table-column>
                        <el-table-column
                                prop="unSendNum"
                                label="未发货数量"
                                width="100"
                                align="center">
                        </el-table-column>

                        <el-table-column
                                prop="planNum"
                                label="已安排数量"
                                width="100"
                                align="center">
                        </el-table-column>
                        <el-table-column
                                prop="planNum"
                                label="未安排数量"
                                width="100"
                                align="center">
                            <template slot-scope="scope">
                                <span style="color:red" v-if="parseFloat(scope.row.unPlanNum) > 0">{{scope.row.unPlanNum}}</span>
                                <span v-else>{{scope.row.unPlanNum}}</span>
                            </template>
                        </el-table-column>

                        <el-table-column
                                prop="goodsAmount"
                                label="合同金额"
                                width="100"
                                align="center">
                        </el-table-column>
                        <el-table-column
                                label="交易方式"
                                width="140"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.deliveryType}}
                            </template>
                        </el-table-column>


                        <el-table-column
                                label="预计发货时间"
                                width="100"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.sendDate}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="预计发货仓库"
                                width="100"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.warehouseName}}
                            </template>
                        </el-table-column>
                      <el-table-column
                        align="center"
                        label="发货类型"
                        fixed="right"
                        width="80">
                        <template slot-scope="scope">
                          {{scope.row.sendType}}
                        </template>
                      </el-table-column>
                      <el-table-column
                        align="center"
                        label="备注"
                        fixed="right"
                        width="150">
                        <template slot-scope="scope">
                          {{scope.row.goodsRemark}}
                        </template>
                      </el-table-column>
                        <el-table-column
                                width="150"
                                fixed="right"
                                label="操作"
                                align="center">
                            <template slot-scope="scope">
                                <!--自提信息，在发货类型为客户自提时显示，安排提货（安排状态为“未安排”，“部分安排”，“全部安排”）一直显示，在“全部安排”不可新增，调整日期在“未安排”显示 -->
                                    <el-button
                                            style="margin-left:0"
                                            type="text"
                                            size="mini"
                                            @click="showDialog3(scope.row)">安排提货
                                    </el-button>
<!--                                    <el-button-->
<!--                                            style="margin-left:0"-->
<!--                                            type="text"-->
<!--                                            size="mini"-->
<!--                                            @click="showDialog(scope.row)">调整日期-->
<!--                                    </el-button>-->
                                    <el-button
                                            v-if="scope.row.sendType=='客户自提'"
                                            style="margin-left:0"
                                            type="text"
                                            size="mini"
                                            @click="showDialog4(scope.row)">自提信息
                                    </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-table
                            v-if="listQuery2.tab==2"
                            v-loading="listLoading"
                            :data="tableData"
                            border
                            style="width: 100%">
                        <el-table-column
                                label="合同号"
                                width="180"
                                align="center">
                            <template slot-scope="scope">
                                <el-link @click="toDetail(scope.row)" type="primary"  style="font-size:12px">
                                    {{scope.row.orderSn}}
                                </el-link>
                                <img src="../../../assets/images/yue.png" v-if="scope.row.isTimeSure == 1" style="vertical-align: middle;"/>
                                <img src="https://pic.moresu.com/FseQ3_RZIxs7oqxHV_58E4pIbY8n" v-if="scope.row.isSure==1" style="width:16px;vertical-align: middle">
                                <img src="https://pic.moresu.com/FoTOVVQAuxPqFyvhBWdO-tQXyeEY" v-if="scope.row.isSure==0" style="width:20px;vertical-align: middle">
                                <img src="https://pic.moresu.com/FhIaQcrC8Mbtqn9EmG4uteNBibd7" v-if="scope.row.activityType == 'paiMai'"  style="vertical-align: middle;width:16px"/>
                            </template>
                        </el-table-column>
                        <el-table-column  label="订单时间" width="100">
                            <template slot-scope="scope">
                                <div>
                                    <span style="font-size:12px;vertical-align: middle">{{scope.row.createTime}}</span>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="商品信息"
                                width="200">
                            <template slot-scope="scope">
                                {{scope.row.goodsSn}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="客户名称"
                                width="200">
                            <template slot-scope="scope">
                                {{scope.row.customerName}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                align="center"
                                label="业务员"
                                width="100">
                            <template slot-scope="scope">
                                {{scope.row.userRealName}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                prop="goodsNum"
                                label="合同数量"
                                width="100"
                                align="center">
                        </el-table-column>
                        <el-table-column
                                label="交易方式"
                                width="140"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.deliveryType}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                align="center"
                                label="发货类型"
                                width="80">
                            <template slot-scope="scope">
                                {{scope.row.sendType}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="期望发货时间"
                                width="150"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.expectSendDate}}
                                <span style="background: red;color:#fff;padding:0 5px;border-radius: 5px" v-if="scope.row.urgentType == '必须'">必须</span>
                                <span style="background:#ff6600;color:#fff;padding:0 5px;border-radius: 5px" v-if="scope.row.urgentType == '可延1-2天'">1-2天</span>
                                <span style="background:#ff9900;color:#fff;padding:0 5px;border-radius: 5px" v-if="scope.row.urgentType == '可延1-2周'">1-2周</span>
                                <span style="background:#0099ff;color:#fff;padding:0 5px;border-radius: 5px" v-if="scope.row.urgentType == '等客户通知'">等待</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="合同约定时间"
                                width="100"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.timeSureDate}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="预计提货时间"
                                width="120"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.takeTime}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="确定能否提货"
                                width="120"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.isSure == 1 ? '确定' : '不确定'}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="提货数量"
                                width="100"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.takeNum}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="已发货数量"
                                width="100"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.actualShipNum}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="提货仓库"
                                width="120"
                                align="center">
                            <template slot-scope="scope">
                                {{scope.row.warehouseName}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="提货信息"
                                width="300">
                            <template slot-scope="scope">
                                <span v-if="scope.row.contactName">联系人：{{scope.row.contactName}}，</span><span v-if="scope.row.contactMobile">联系电话{{scope.row.contactMobile}}</span>
                                <div>{{scope.row.takeAddress}}</div>
                            </template>
                        </el-table-column>
                        <el-table-column
                                width="150"
                                fixed="right"
                                label="操作"
                                align="center">
                            <template slot-scope="scope">
                                <!--自提信息，在发货类型为客户自提时显示，安排提货（安排状态为“未安排”，“部分安排”，“全部安排”）一直显示，在“全部安排”不可新增，调整日期在“未安排”显示 -->
                                    <el-button
                                            style="margin-left:0"
                                            type="text"
                                            size="mini"
                                            @click="showDialog2('edit',scope.row,'yi')">编辑
                                    </el-button>
                                    <el-button
                                            style="margin-left:0"
                                            type="text"
                                            size="mini"
                                            @click="delRow(scope.row)">取消
                                    </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div v-if="listQuery2.tab==1" style="color:#606266;margin-top:20px">未安排总计：<span style="font-weight: bold">{{unPlanNum}}</span></div>
                <div v-if="listQuery2.tab==2" style="color:#606266;margin-top:20px">已安排（未发货）总计：<span style="font-weight: bold">{{hasPlanNum}}</span></div>
                <div class="pagination-container" style="float:right;margin-top:-20px">
                    <el-pagination
                            background
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            layout="total, sizes,prev, pager, next,jumper"
                            :current-page.sync="listQuery2.pageNum"
                            :page-size="listQuery2.pageSize"
                            :page-sizes="[10,15,20]"
                            :total="count">
                    </el-pagination>
                </div>


        <!--日期调整弹窗-->
        <el-dialog
                :close-on-click-modal="false"
                :beforeClose="handleClose"
                title="日期调整"
                :visible.sync="dialogVisible"
                width="400px">
            <el-form :model="dataForm" size="mini" label-width="120px"  ref="dataForm" :rules="rules">
                <el-form-item label="期望发货时间：">
                    {{dataForm.hopeDate}}
                </el-form-item>
                <el-form-item label="调整日期："  prop="areaIds">
                    <el-date-picker
                            v-model="dataForm.date"
                            type="date"
                            placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                  <el-button @click="handleClose">取 消</el-button>
                  <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确 定</el-button>
              </span>
        </el-dialog>

        <!--调整发货时间弹窗-->
        <el-dialog
                :close-on-click-modal="false"
                :beforeClose="handleClose6"
                title="调整发货时间"
                :visible.sync="dialogVisible6"
                width="400px">
            <el-form :model="timeForm" size="mini" label-width="120px"  ref="timeForm" :rules="rules6">
                <el-form-item label="发货时间："  prop="takeTime">
                    <el-date-picker
                            value-format="yyyy-MM-dd"
                            v-model="timeForm.takeTime"
                            type="date"
                            placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="备注：" prop="remark">
                    <el-input v-model="timeForm.remark" :autosize="{ minRows: 2, maxRows: 6}" type="textarea"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                  <el-button @click="handleClose6">取 消</el-button>
                  <el-button type="primary" @click="handleConfirm6" :loading="btnLoading6">确 定</el-button>
              </span>
        </el-dialog>

        <!--新增/编辑安排提货弹窗-->
        <el-dialog
                :close-on-click-modal="false"
                :beforeClose="handleClose2"
                title="安排提货"
                :visible.sync="dialogVisible2"
                width="800px">
            <el-row>
               <el-col :span="10">
                    <div style="font-weight: bold;margin-bottom:10px;">需安排提货合同信息</div>
                    <el-form>
                      <el-form-item label="商品信息：" style="margin-bottom:0">
                            {{ cutItem.goodsSn }}
                      </el-form-item>
                      <el-form-item label="客户名称：" style="margin-bottom:0">
                        {{ cutItem.customerName }}
                      </el-form-item>
                      <el-form-item label="业务员：" style="margin-bottom:0">
                        {{ cutItem.userRealName }}
                      </el-form-item>
                      <el-form-item label="合同数量：" style="margin-bottom:0">
                        {{ cutItem.goodsNum }}
                      </el-form-item>
                      <el-form-item label="未发货数量：" style="margin-bottom:0" v-show="handleConfirm2Tab !='yiti'">
                        {{ cutItem.unSendNum }}
                      </el-form-item>
                      <el-form-item label="已安排数量：" style="margin-bottom:0" v-show="handleConfirm2Tab !='yiti'">
                        {{ cutItem.planNum }}
                      </el-form-item>
                      <el-form-item label="未安排数量：" style="margin-bottom:0" v-show="handleConfirm2Tab !='yiti'">
                        {{ cutItem.unPlanNum }}
                      </el-form-item>
                      <el-form-item label="发货类型：" style="margin-bottom:0">
                        {{ cutItem.sendType }}
                      </el-form-item>
                      <el-form-item label="预计发货仓库：" style="margin-bottom:0" v-show="handleConfirm2Tab !='yiti'">
                        {{ cutItem.warehouseName }}
                      </el-form-item>
                      <el-form-item label="订单备注：" style="margin-bottom:0" >
                        <div style="color:red;font-size:16px;">{{ cutItem.goodsRemark }}</div>
                      </el-form-item>
                      <el-form-item label="结算方式：" style="margin-bottom:0">
                        {{ cutItem.orderRemark  }}
                      </el-form-item>
                    </el-form>
               </el-col>
              <el-col :span="14" style="border-left:1px solid #DCDFE6">
                  <el-form :model="sendForm" size="mini" label-width="100px"  ref="sendForm" :rules="rules2">
                  <el-form-item label="提货时间："  prop="takeTime">
                    <el-date-picker
                      :picker-options="pickerOptions"
                      value-format="yyyy-MM-dd"
                      v-model="sendForm.takeTime"
                      style="display: inline-block;width:150px"
                      type="date"
                      placeholder="选择日期">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item label="提货概率：" prop="isSure">
                    <el-radio-group v-model="sendForm.isSure">
                      <el-radio :label="1">确定<span style="color:#999;padding-left:5px">(保证准时发货)</span></el-radio>
                      <el-radio :label="0">不确定</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <el-form-item label="提货数量："  prop="takeNum">
                    <el-input v-model="sendForm.takeNum"></el-input>
                  </el-form-item>
                  <el-form-item label="商品包装："  prop="goodsWeight">
                    <el-input v-model="sendForm.goodsWeight" style="width:150px"></el-input> <span>kg/包</span>
                    <el-checkbox v-model="sendForm.isHasTray">含托</el-checkbox>
                  </el-form-item>
                  <el-form-item label="提货类型：" prop="planSendType" v-if="sendForm.isSure == 1">
                    <el-select v-model="sendForm.planSendType">
                      <el-option value="工厂发货">工厂发货</el-option>
                      <el-option value="运联发货">运联发货</el-option>
                      <el-option value="自提">自提</el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="采购合同：" prop="purchaseOrderId">
                    <el-select v-model="sendForm.purchaseOrderId" clearable style="width:100%" filterable>
                      <el-option :value="item.purchaseOrderId" :label="item.purchaseSn+'/'+item.goodsSn+'/'+item.goodsNum+'吨/'+'/￥'+item.goodsPrice+'/可提'+item.unTakeNum+'吨'+'/'+item.supplierName" v-for="item in purchaseOrderList" :key="item.purchaseOrderId"></el-option>
                    </el-select>
                  </el-form-item>
                  <div v-if="sendForm.isSure == 1 && sendForm.planSendType != '工厂发货'">
                    <el-form-item label="仓库：" prop="warehouseName">
                      <el-select
                        style="width:150px;display: inline-block"
                        clearable
                        v-model="sendForm.warehouseName"
                        filterable
                        remote
                        reserve-keyword
                        placeholder="请输入关键词"
                        @change="changeWarehouseId"
                        :remote-method="remoteMethod2"
                        :loading="loading">
                        <el-option
                          v-for="item in options2"
                          :key="item.warehouseName"
                          :label="item.warehouseName"
                          :value="item.warehouseName">
                        </el-option>
                      </el-select>
                      <el-button type="text" style="display: inline-block" @click="showDialog5">增加仓库</el-button>
                    </el-form-item>
                    <el-form-item label="联系人："  prop="contactName">
                      <el-input v-model="sendForm.contactName"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号："  prop="contactMobile">
                      <el-input v-model="sendForm.contactMobile"></el-input>
                    </el-form-item>
                    <el-form-item label="提货地点："  prop="takeAddress">
                      <el-input v-model="sendForm.takeAddress"></el-input>
                    </el-form-item>
                    <el-form-item label="注意事项：" >
                      <el-input :autosize="{ minRows: 2, maxRows: 6}" type="textarea" v-model="sendForm.takeRemark"></el-input>
                    </el-form-item>

                  </div>

                </el-form>
              </el-col>
            </el-row>

            <span slot="footer" class="dialog-footer">
                  <el-button @click="handleClose2">取 消</el-button>
                  <el-button type="primary" @click="handleConfirm2" :loading="btnLoading2">确 定</el-button>
              </span>
        </el-dialog>

        <!--提货信息弹窗-->
        <el-dialog
                :beforeClose="handleClose3"
                :close-on-click-modal="false"
                title="提货信息"
                :visible.sync="dialogVisible3"
                width="800px">
            <div><el-button size="small" type="primary" @click="showDialog2('add')">新增提货</el-button></div>
            <el-table
                    v-loading="listLoading"
                    :data="goodsPlanList"
                    border
                    style="width: 100%;margin:20px 0">
                <el-table-column
                        align="center"
                        label="提货时间"
                        width="100">
                    <template slot-scope="scope">
                        {{scope.row.takeTime}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="确定能否提货"
                        width="120"
                        align="center">
                    <template slot-scope="scope">
                        {{scope.row.isSure == 1 ? '确定' : '不确定'}}
                    </template>
                </el-table-column>
                <el-table-column
                        width="100"
                        align="center"
                        label="提货数量">
                    <template slot-scope="scope">
                        {{scope.row.takeNum}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="仓库信息"
                        width="150"
                        align="center">
                    <template slot-scope="scope">
                        {{scope.row.warehouseName}}
                    </template>
                </el-table-column>
                <el-table-column  label="联系人" width="100" align="center">
                    <template slot-scope="scope">
                        <div>
                            <span style="font-size:12px;vertical-align: middle">{{scope.row.contactName}}</span>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column
                        label="手机号"
                        width="100"
                        align="center">
                    <template slot-scope="scope">
                        {{scope.row.contactMobile}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="提货地点"
                        width="260">
                    <template slot-scope="scope">
                        {{scope.row.takeAddress}}
                    </template>
                </el-table-column>
<!--                <el-table-column-->
<!--                        prop="takeRemark"-->
<!--                        label="备注"-->
<!--                        width="300"-->
<!--                        align="center">-->
<!--                </el-table-column>-->
                <el-table-column
                        width="100"
                        fixed="right"
                        label="操作"
                        align="center">
                    <template slot-scope="scope">
                        <el-button
                                style="margin-left:0"
                                type="text"
                                size="mini"
                                @click="showDialog2('edit',scope.row)">编辑
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>

        <!--自提信息弹窗-->
        <el-dialog
                :close-on-click-modal="false"
                title="司机信息"
                :visible.sync="dialogVisible4"
                width="800px">
            <el-table
                    v-loading="listLoading4"
                    :data="selfTakeList"
                    border
                    style="width: 100%">
                <el-table-column
                        label="司机姓名"
                        width="100"
                        align="center">
                    <template slot-scope="scope">
                        {{scope.row.driverName}}
                    </template>
                </el-table-column>
                <el-table-column  label="手机号" width="100" align="center">
                    <template slot-scope="scope">
                        {{scope.row.driverMobile}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="车牌号"
                        width="100"
                        align="center">
                    <template slot-scope="scope">
                        {{scope.row.driverCardNo}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="提货时间"
                        width="100"
                        align="center">
                    <template slot-scope="scope">
                        {{scope.row.takeTime}}
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        label="提货数量"
                        width="100">
                    <template slot-scope="scope">
                        {{scope.row.takeNum}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="备注">
                    <template slot-scope="scope">
                        {{scope.row.takeRemark}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="chargeUserName"
                        label="负责人"
                        width="100"
                        align="center">
                </el-table-column>
            </el-table>
        </el-dialog>

        <!--增加仓库-->
        <warehouseInfo ref="warehouseInfo" @getList="getWarehouseList"></warehouseInfo>

      <!--取消排货-->
      <el-dialog
        :close-on-click-modal="false"
        :beforeClose="handleClose6"
        title="取消排货"
        :visible.sync="dialogVisible7"
        width="500px">
        <el-form :model="cancelForm" size="mini" label-width="100px"  ref="cancelForm" :rules="rules7">
          <el-form-item label="取消类型：" prop="cancelType">
            <el-radio-group v-model="cancelForm.cancelType">
              <el-radio label="物流"></el-radio>
              <el-radio label="销售"></el-radio>
              <el-radio label="采购"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="运费损失：" >
            <el-input-number v-model="cancelForm.lossFreight"></el-input-number>
          </el-form-item>
          <el-form-item label="取消原因：" prop="cancelRemark">
            <el-input :autosize="{ minRows: 2, maxRows: 6}" type="textarea" v-model.trim="cancelForm.cancelRemark"></el-input>
          </el-form-item>

        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose7">取 消</el-button>
          <el-button type="primary" @click="handleConfirm7" :loading="btnLoading7">确 定</el-button>
      </span>
      </el-dialog>

    </div>
</template>


<script>
    import {getPlanList,goodsList,getUnPlanList,warehouseList,getWarehouseDetail,postPlanGoods,warehouseAdd,getPlanGoodsList,getGoodsPlanList,changePlanDate,cancelGoodsPlan,selfTakeInfo,ordGoodsFilter,planGoodsFilter} from '@/api/company'
    import {getAddressList,getUserOption,getCustomerOption} from '@/api/partner'
    import {formatDate} from '@/utils/date';
    import store from '@/store'
    import warehouseInfo from './warehouseInfo.vue'
    import { mapGetters } from 'vuex'
    import fullCalendar from '@/views/pums/vue-fullcalendar/fullCalendar.vue'
    import {needTakePurchaseGoods} from "../../../api/partner";
    const defaultListQuery={
        date: [],
        kingId:null,
        customerName:null,
        userId:null,
        orderSn:'',
        goodsName:'',
    };
    const defaultListQuery2 = {
        tab:'1',
        pageNum: 1,
        pageSize: 10,
        date: [],
        kingId:[],
        customerName:null,
        userId:null,
        orderSn:'',
        goodsName:'',
        isSure:null,
        sendTypeName:'',
        warehouseName:'',
        orderBy:'default'
    };
    const defaultDataForm={
        date:null,
        hopeDate:''

    };
    const defaultTimeForm={
        takeTime:'',
        remark:''
    };

    const defaultSendForm={
        "ogId" : null,          //合同商品记录ID
        "warehouseName"   : null,    //仓库ID
        "contactName"   : "",   //联系人
        "contactMobile" : "",   //联系人手机号
        "takeAddress"   : "",    //提货地址
        "takeTime"      : "",    //提货时间
        "takeNum"       : null,    //提货数量
        "takeRemark"    : ""   , //备注(提货注意事项)
        isSure:1,
        planSendType:'',
        purchaseOrderId:'',  //关联采购合同
        goodsWeight:'',
        isHasTray:false
    };
    const defaultCancelForm={
      dpgId:'',
      cancelType : "", //取消类型
      "cancelRemark" : "", //取消原因
      "lossFreight" : 0 ,//损失运费
    }

    export default {
        name: "index",
        components : {
            'full-calendar': fullCalendar,
              warehouseInfo:warehouseInfo
        },
        data(){
            const isvalidatePurchaseOrderId = (rule, value, callback) => {
              if(this.sendForm.planSendType == '工厂发货' && !value ){
                callback(new Error('请关联采购订单号'))
              }else if(this.sendForm.planSendType == '运联发货' && this.curWarehouse.isSelfBusiness==0 && !value ){
                callback(new Error('请关联采购订单号'))
              } else if(this.sendForm.planSendType == '自提' && this.curWarehouse.isSelfBusiness==0 && !value ){
                callback(new Error('请关联采购订单号'))
              } else {
                callback()
              }
            };

            return {
                listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
                listQuery2:JSON.parse(JSON.stringify(defaultListQuery2)),
                tableData: [],
                count: 0,
                listLoading: false,
                customerStateList: [],
                userOptionList:[],
                roles:store.getters.roles ? store.getters.roles : [],
                orderStateList:[],
                JDupdate:'',
                listAmount:0,
                statisticsCount:0,
                statisticsAmount:0,
                statisticsGoodsNum:0,
                fcEvents:[],
                dialogVisible:false,
                rules:{},
                btnLoading:false,
                dataForm:JSON.parse(JSON.stringify(defaultDataForm)),
                dialogVisible2:false,
                rules2:{
                    warehouseName   :[{required: true, message: '请选择仓库', trigger: 'change'},],
                    contactName   : [{required: true, message: '请输入联系人', trigger: 'blur'},],
                    contactMobile : [{required: true, message: '请输入联系人手机号', trigger: 'blur'},],
                    takeAddress   : [{required: true, message: '请输入提货地址', trigger: 'blur'},],
                    takeTime      : [{required: true, message: '请输入提货时间', trigger: 'blur'},],
                    takeNum       : [{required: true, message: '请输入提货数量', trigger: 'blur'},],
                    planSendType      : [{required: true, message: '请选择提货类型', trigger: 'change'},],
                    purchaseOrderId : [{required: true, validator: isvalidatePurchaseOrderId, trigger: 'change'},],
                    goodsWeight: [{required: true, message: '请输入商品包装', trigger: 'blur'},],
                    isSure:[{required: true, message: '请选择提货概率', trigger: 'change'},],
                },
                btnLoading2:false,
                sendForm:JSON.parse(JSON.stringify(defaultSendForm)),
                dialogVisible3:false,
                sendType:'',

                dialogVisible4:false,
                kingId:'',
                currentMonth:'',
                loading:false,
                options:[],
                loading2:false,
                options2:[],
                ogId:'',


                dialogVisible6:false,
                rules6:{
                    takeTime: [{required: true, message: '请选择发货时间', trigger: 'change'},],
                    remark:[{required: true, message: '请输入备注', trigger: 'blur'},],
                },
                btnLoading6:false,
                timeForm:JSON.parse(JSON.stringify(defaultTimeForm)),
                goodsPlanList:[],
                selfTakeList:[],
                listLoading4:false,
                allTakeNum:'',
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() < Date.now() - 8.64e7
                    }
                },
                handleConfirm2Tab:'',
                options4:[],
                loading4:false,
                kingIds:[],
                customers:[],
                users:[],
                querySearchList:[],
                unPlanNum:'',
                hasPlanNum:'',
                cutItem:{},
                purchaseOrderList:[],
                curWarehouse:{},

                btnLoading7:false,
                dialogVisible7:false,
                cancelForm:JSON.parse(JSON.stringify(defaultCancelForm)),
                rules7:{
                  cancelType:[{required: true, trigger: 'blur' ,message: '此项必填',}],
                  cancelRemark:[{required: true, trigger: 'blur' ,message: '此项必填',}],
                },
            }
        },
        created() {
            this.getUserOptionList();
        },
        filters: {
            formatCreateTime(time) {
                if(time){
                    let date = new Date(time);
                    return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
                }else{
                    return '--'
                }
            },
            fifterState(val){
                if(val == 0){
                    return '未安排'
                }else if(val == 1){
                    return '部分安排'
                }else if(val == 2){
                    return '已安排'
                }
            },
        },
        methods:{
            //获取关联采购单
          getPOrderList(){
            needTakePurchaseGoods({goodsKingId:this.cutItem.goodsKingId}).then((res)=>{
                this.purchaseOrderList = res;
            })
          },
            //获取当月数量
            getMonthPlanList(){
                console.log("this.listQuery", this.listQuery)
                let now = new Date(this.listQuery.date[0]);

                let nowMonth = now.getMonth(); //当前月
                let nowYear = now.getFullYear(); //当前年
                //本月的开始时间
                let monthStartDate = new Date(nowYear, nowMonth, 1);
                let startDate = formatDate(monthStartDate, 'yyyy-MM-dd');
                let pa = JSON.parse(JSON.stringify(this.listQuery));
                pa.date = startDate;
                getPlanList(pa).then((res)=>{
                    this.fcEvents = res;
                });
            },

           //获取员工下拉选项
            getUserOptionList(){
                getUserOption().then((res)=>{
                    this.userOptionList = res;
                })
            },

            //客户名称输入匹配
            querySearch(queryString){
                getCustomerOption({keywords:queryString}).then((res)=>{
                    this.querySearchList = res;
                })
            },
            //选择客户名称
            handleSelectCustomerName(item){
                this.listQuery.customerName = item;
                this.changeMonth('','',this.currentMonth)
            },

            //切换用户
            changeUserId(){
                this.changeMonth('','',this.currentMonth)
            },

            //切换搜索商品
            changekingId(val){
                this.listQuery.kingId = val;
                this.changeMonth('','',this.currentMonth)
            },
            //获取指定合同排货列表
            getGoodsPlanListData(ogId){
                getGoodsPlanList({ogId:ogId}).then((res)=>{
                    this.goodsPlanList = res
                })
            },

          handleClose7(){
            this.dialogVisible7 = false;
          },
          handleConfirm7(){
            this.$refs.cancelForm.validate((valid) => {
              if (valid) {
                this.btnLoading7 = false;
                let data = JSON.parse(JSON.stringify(this.cancelForm));
                cancelGoodsPlan(data).then(response => {
                  this.btnLoading6 = false;
                  this.$message({
                    message: '提交成功',
                    type: 'success',
                    duration: 1000
                  });
                  this.handleClose7()
                  this.getList();
                  this.getMonthPlanList();
                }).catch(() => {
                  this.btnLoading7 = false;
                })
              }
            })
          },

            //取消发货
            delRow(item){
                this.dialogVisible7 = true;
                this.cancelForm.dpgId = item.dpgId;
            },

            //显示调整发货时间
            showDialog6(item){
                this.dialogVisible6 = true;
                this.timeForm = JSON.parse(JSON.stringify(defaultTimeForm));
                this.timeForm.takeTime = item.takeTime;
                this.timeForm.dpgId = item.dpgId
            },

            //关闭调整发货时间
            handleClose6(){
                this.dialogVisible6 = false;
                this.$refs.timeForm.clearValidate();
            },

            //提交调整发货时间
            handleConfirm6(){
                this.$refs['timeForm'].validate((valid) => {
                    if (valid) {
                        this.btnLoading6 = true;
                        let pa = JSON.parse(JSON.stringify(this.timeForm));
                        changePlanDate(pa).then(()=>{
                            this.btnLoading6 = false;
                            this.dialogVisible6 = false;
                            this.getList();
                            this.getMonthPlanList();
                        }).catch(()=>{
                            this.btnLoading6 = false;
                        })
                    }
                })
            },

            //显示增加仓库弹窗
            showDialog5(){
              this.$refs.warehouseInfo.showDialog('add',null);
            },


            //仓库列表
            getWarehouseList(keywords){
              warehouseList({keywords:keywords}).then((res)=>{
                this.options2 = res.list;
                this.btnLoading5 = false;
              })
            },

            remoteMethod(query) {
                if (query !== '') {
                    this.loading = true;
                    goodsList({keywords:query}).then((res)=>{
                        this.options = res.list;
                        this.loading = false;
                    })
                } else {
                    this.options = [];
                    this.loading = false;
                }
            },
            //搜索品名
            remoteMethod4(query) {
                if (query !== '') {
                    this.loading4 = true;
                    goodsList({keywords:query}).then((res)=>{
                        this.options4 = res.list;
                        this.loading4 = false;
                    })
                } else {
                    this.options = [];
                    this.loading = false;
                }
            },
            //搜索仓库
            remoteMethod2(query) {
                if (query !== '') {
                    this.loading2 = true;
                    warehouseList({keywords:query}).then((res)=>{
                        this.options2 = res.list;
                        this.loading2 = false;
                    })
                } else {
                    this.options = [];
                    this.loading2 = false;
                }
            },

            changeWarehouseId(val){
                let curWarehouse = this.options2.find((el)=>{
                        return el.warehouseName == val
                    });
                this.curWarehouse = JSON.parse(JSON.stringify(curWarehouse));
                if(curWarehouse.warehouseId){
                    getWarehouseDetail({warehouseId:curWarehouse.warehouseId}).then((res)=>{
                        this.sendForm.contactName  = res.contactName;
                        this.sendForm.contactMobile = res.contactMobile;
                        this.sendForm.takeAddress = res.address;
                        this.sendForm.takeRemark = res.remark;
                    });
                }else{
                    this.sendForm = JSON.parse(JSON.stringify(defaultSendForm));
                }
            },

            //显示自提信息
            showDialog4(item){
                this.dialogVisible4 = true;
                this.listLoading4 = true;
                selfTakeInfo({orderId:item.orderId}).then((res)=>{
                    this.selfTakeList = res;
                    this.listLoading4 = false
                }).catch(()=>{
                    this.listLoading4 = false
                })
            },
            //显示提货信息
            showDialog3(item){
                this.dialogVisible3 = true;
                this.ogId = item.ogId;
                this.allTakeNum = item.goodsNum;
                this.cutItem = JSON.parse(JSON.stringify(item));
                this.getGoodsPlanListData(this.ogId);
            },
            //关闭提货
            handleClose3(){
                this.dialogVisible3 = false;
                this.getList();
                this.getMonthPlanList();
            },
            //显示调整日期
            showDialog(item){
                this.dialogVisible = true;
                this.dataForm = JSON.parse(JSON.stringify(defaultDataForm));
                    this.dataForm.warehouseName = item.warehouseName;
                    this.dataForm.contactName = item.contactName;
                    this.dataForm.contactMobile = item.contactMobile;
            },

            //关闭调整日期
            handleClose(){
                this.dialogVisible = false;
                this.$refs.dataForm.clearValidate();
            },

            //提交调整日期
            handleConfirm(){
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.btnLoading = true;
                        let fn = this.type == 'add' ? warehouseAdd : warehouseEdit;
                        let pa = JSON.parse(JSON.stringify(this.dataForm));
                        fn(pa).then(()=>{
                            this.btnLoading = false;
                            this.dialogVisible = false;
                            this.getList()
                        }).catch(()=>{
                            this.btnLoading = false;
                        })
                    }
                })
            },

            //显示安排提货
            showDialog2(type,item,tab){
                this.dialogVisible2 = true;
                this.handleConfirm2Tab = tab ? 'yiti' : 'xuti';
                this.sendForm = JSON.parse(JSON.stringify(defaultSendForm));
                this.options2 = [];
                if(type == 'add'){
                    let num = 0;
                    this.goodsPlanList.forEach((el)=>{
                        num = num + parseFloat(el.takeNum);
                    });
                    this.sendForm.takeNum = (parseFloat(this.allTakeNum)- num).toFixed(4)
                }

                if(type == 'edit'){
                    this.sendForm.warehouseName = item.warehouseName;
                    this.sendForm.contactName = item.contactName;
                    this.sendForm.contactMobile = item.contactMobile;
                    this.sendForm.takeAddress = item.takeAddress;
                    this.sendForm.takeTime = item.takeTime;
                    this.sendForm.takeNum = item.takeNum;
                    this.sendForm.takeRemark = item.takeRemark;
                    this.sendForm.isSure = item.isSure;
                    this.sendForm.planSendType = item.planSendType;
                    this.sendForm.dpgId = item.dpgId;
                    this.sendForm.purchaseOrderId = item.purchaseOrderId == 0 ? '' : item.purchaseOrderId;
                    this.sendForm.goodsWeight = item.goodsWeight;
                    this.sendForm.isHasTray = item.isHasTray == 1 ? true : false;
                    this.options2.push({warehouseName:item.warehouseName});

                }
                if(this.handleConfirm2Tab == 'yiti'){
                    this.ogId = item.ogId;
                    this.sendForm.planSendType = item.planSendType;
                    this.cutItem.goodsSn = item.goodsSn;
                    this.cutItem.customerName = item.customerName;
                    this.cutItem.userRealName = item.userRealName;
                    this.cutItem.goodsNum = item.goodsNum;
                    this.cutItem.sendType = item.sendType;
                    this.cutItem.goodsKingId = item.goodsKingId;
                    this.cutItem.goodsRemark = item.goodsRemark;
                    this.cutItem.orderRemark = item.orderRemark
                }
               this.getPOrderList();
            },

            //关闭安排提货
            handleClose2(){
                this.dialogVisible2 = false;
                this.$refs.sendForm.clearValidate();
            },

            //提交安排提货
            handleConfirm2(){
                this.$refs['sendForm'].validate((valid) => {
                    if (valid) {
                        this.btnLoading2 = true;
                        let pa = JSON.parse(JSON.stringify(this.sendForm));
                        pa.ogId = this.ogId;
                        if(pa.isSure == 0 || pa.planSendType == '工厂发货'){
                            pa.warehouseName = '';
                            pa.contactName = '';
                            pa.contactMobile = '';
                            pa.takeAddress = '';
                            pa.takeRemark = '';
                            pa.planSendType = pa.isSure == 0 ? '' : pa.planSendType
                        }
                        postPlanGoods(pa).then(()=>{
                            this.btnLoading2 = false;
                            this.dialogVisible2 = false;
                            if(this.handleConfirm2Tab == 'xuti'){ //需提
                                this.getGoodsPlanListData(this.ogId);
                            }else{//已提
                                this.getList();
                                this.getMonthPlanList();
                            }
                        }).catch(()=>{
                            this.btnLoading2 = false;
                        })
                    }
                })
            },

            //重置列表搜索条件
            resetListQuery2(){
                this.listQuery2.pageNum = 1;
                this.listQuery2.kingId = this.listQuery.kingId;
                // let king = this.options.find((el)=>{
                //     return el.kingId == this.listQuery.kingId;
                // });
                // this.kingIds = [];
                // if(king){
                //     this.kingIds.push({goodsSn:king.goodsSn,goodsKingId:king.kingId});
                // }
                this.listQuery2.customerName = this.listQuery.customerName;
                this.listQuery2.userId = this.listQuery.userId;
                this.listQuery2.orderSn = this.listQuery.orderSn;
                this.listQuery2.goodsName = this.listQuery.goodsName;

            },

            //获取筛选项
            getOrdGoodsFilter(startDate,endDate){
                let pa = {};
                pa.date = [];
                pa.date.push(startDate,endDate);
                pa.kingId = this.listQuery.kingId;
                pa.customerName = this.listQuery.customerName;
                pa.userId = this.listQuery.userId;
                pa.orderSn = this.listQuery.orderSn;
                pa.goodsName = this.listQuery.goodsName;
                let fn = this.listQuery2.tab == 1 ? ordGoodsFilter : planGoodsFilter;
                fn(pa).then((res)=>{
                    this.kingIds = res.goodsList;
                    this.customers = res.customerList;
                    this.users = res.userList;
                });
            },

            //切换月
            changeMonth(start,end,current){
                this.currentMonth = current;
                this.fcEvents = [];
                let pa = JSON.parse(JSON.stringify(this.listQuery));
                pa.date = current;
                getPlanList(pa).then((res)=>{
                    this.fcEvents = res;
                });
                let now = new Date(current);
                let nowMonth = now.getMonth(); //当前月
                let nowYear = now.getFullYear(); //当前年
                //本月的开始时间
                let monthStartDate = new Date(nowYear, nowMonth, 1);
                //本月的结束时间
                let monthEndDate = new Date(nowYear, nowMonth+1, 0);
                let startDate = formatDate(monthStartDate, 'yyyy-MM-dd');
                let endDate = formatDate(monthEndDate, 'yyyy-MM-dd');
                this.listQuery.date = [];
                this.listQuery.date.push(startDate,endDate);
                this.listQuery2.date = [];
                this.listQuery2.date.push(startDate,endDate);
                this.resetListQuery2();
                this.getList();
                this.getOrdGoodsFilter(startDate,endDate);
            },
            //点击日
            dayClick(date,jsEvent){
                let i = -1;
                let $e  = $(jsEvent.target).parents(".events-day").size()==1 ? $(jsEvent.target).parents(".events-day") : $(jsEvent.target);
                if(!$e.hasClass('not-cur-month')){
                    i =  $(".events-day").index($e);
                };
                if(i!=-1){
                    $(".dates-bg").find(".day-cell").removeClass('choose');
                    $(".dates-bg").find(".day-cell").eq(i).addClass('choose')
                };
                let dd = formatDate(date, 'yyyy-MM-dd');
                this.listQuery.date = [];
                this.listQuery.date.push(dd,dd);
                this.listQuery2.date = [];
                this.listQuery2.date.push(dd,dd);
                this.resetListQuery2();
                this.getList();
                this.getOrdGoodsFilter(dd,dd);
            },
            handleSizeChange(val){
                this.listQuery2.pageNum = 1;
                this.listQuery2.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val){
                this.listQuery2.pageNum = val;
                this.getList();
            },
            selectTab(key){
                this.listQuery2.tab = key;
                this.resetListQuery2();
                this.handleSearchList();
                this.getOrdGoodsFilter(this.listQuery2.date[0],this.listQuery2.date[1]);
            },
            handleSearchList(){
                this.listQuery2.pageNum = 1;
                this.getList();
            },

            //获取排货列表
            getList() {
                this.listLoading = true;
                let fn = this.listQuery2.tab == 1 ? getUnPlanList : getPlanGoodsList;
                if(!this.listQuery2.kingId){
                    this.listQuery2.kingId = this.listQuery.kingId;
                }
                if(this.listQuery2.isSure === ''){
                    this.listQuery2.isSure = null
                }
                if(this.listQuery2.planDeliverState === ''){
                    this.listQuery2.planDeliverState = null
                }
                fn(this.listQuery2).then(response => {
                    this.tableData = response.list;
                    this.count = response.count;
                    this.hasPlanNum = response.hasPlanNum ? response.hasPlanNum : '';
                    this.unPlanNum = response.unPlanNum ? response.unPlanNum : '';
                    this.listLoading = false;
                }).catch(()=>{
                    this.listLoading = false;
                });
            },

            //去详情页
            toDetail(item){
                let routeData = this.$router.resolve({name:'purchaseDetail',query:{id:item.orderId,type:'see'}});
                window.open(routeData.href);
            },

        },
    }
</script>

<style lang="scss">
    .day-cell.choose{
        background: #e6f1fe;
    }

    .full-calendar-body .dates .week-row .day-cell.today.choose{
        background: #e6f1fe !important;
    }
    .full-calendar-body .dates .dates-events .events-week .events-day{
        /*min-height: 60px !important;*/
    }
    .full-calendar-body .dates .week-row .day-cell{
        /*min-height: 60px !important;*/
    }
    .full-calendar-header{
        background: #409EFF;
        height: 40px;
        line-height: 40px;
        color: #fff;
        font-size: 16px;
    }
    .full-calendar-body .weeks{
        height: 30px;
        line-height: 30px;
        background: #72b8ff;
        color: #fff;
        font-size:14px;
    }
    .full-calendar-body .weeks .week{
        border-right: 0 !important;
    }
    .comp-full-calendar{
        background: #fff;
        max-width: 100% !important;
        box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
        margin: 0 !important;
        padding:0px !important;
    }
    .full-calendar-body{
        margin-top:0 !important;
    }


</style>
